import os
import time

class ChatTTSConfig:
    AUDIO_CACHE_DIR = "chat_tts_audio_cache"
    DEFAULT_SPEED = 150
    DEFAULT_VOLUME = 0.9
    DEFAULT_VOICE = "auto"
    MAX_FILE_AGE_HOURS = 24
    LOG_DIR = "logs"
    LOG_FILE = "chat_tts_app.log"

    def __init__(self):
        # 创建必要的目录
        os.makedirs(self.AUDIO_CACHE_DIR, exist_ok=True)
        os.makedirs(self.LOG_DIR, exist_ok=True)

    def clean_old_files(self):
        max_age = self.MAX_FILE_AGE_HOURS * 3600  # 转换为秒
        now = time.time()
        deleted_count = 0
        for root, dirs, files in os.walk(self.AUDIO_CACHE_DIR):
            for file in files:
                file_path = os.path.join(root, file)
                file_age = now - os.path.getmtime(file_path)
                if file_age > max_age:
                    os.remove(file_path)
                    deleted_count += 1
        return deleted_count

chat_tts_config = ChatTTSConfig()